from app.core import info_interactive_with_pt
from app.core import interactive_with_backup_service

from app.core.config import mysql_backup_before_execute_url


def get_group_id_by_instance_info(mysql_host, mysql_port):
    get_group_id_url = "/user_manage/mysql_user_manage/get_instance_group_id"
    data = {"mysql_host": mysql_host, "mysql_port": mysql_port}
    info_from_cmdb = info_interactive_with_pt(get_group_id_url, call_system='cmdb', method='GET', args_send=data)
    group_id = info_from_cmdb.get('msg')
    return group_id


def get_master_info(group_id: int):
    get_master_suffix_url = "/db_install/base/mymaster"
    data = {"group_id": group_id}
    # print(data)
    master_info = info_interactive_with_pt(get_master_suffix_url, call_system='dbpt', method='POST', args_send=data)
    return master_info.get('data')


def get_mysql_user_password(mysql_host, mysql_port, user_name='a_dba_rw'):
    return 'X5KL!qm_WuD4wJ0T'


def call_mysql_backup(backup_sql, args_send):
    args_send.update({"backup_sql": backup_sql})
    base_url = mysql_backup_before_execute_url
    return interactive_with_backup_service(base_url, args_send, method='POST')
